package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSupplierContact;
import com.ruoyi.system.service.ISysSupplierContactService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务商联系方式Controller
 * 
 * @author ruoyi
 * @date 2022-07-10
 */
@Api(tags = "服务商模块管理")
@RestController
@RequestMapping("/system/contact")
public class SysSupplierContactController extends BaseController
{
    @Autowired
    private ISysSupplierContactService sysSupplierContactService;

    /**
     * 查询服务商联系方式列表
     */
    @ApiOperation(value = "查询服务商联系方式列表")
    //@PreAuthorize("@ss.hasPermi('system:contact:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSupplierContact sysSupplierContact)
    {
        if(!isAdmin()){
            sysSupplierContact.setDeptId(getCompanyId());
        }
        startPage();
        List<SysSupplierContact> list = sysSupplierContactService.selectSysSupplierContactList(sysSupplierContact);
        return getDataTable(list);
    }

    /**
     * 导出服务商联系方式列表
     */
   // @PreAuthorize("@ss.hasPermi('system:contact:export')")
    @Log(title = "服务商联系方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSupplierContact sysSupplierContact)
    {
        if(!isAdmin()){
            sysSupplierContact.setDeptId(getCompanyId());
        }
        List<SysSupplierContact> list = sysSupplierContactService.selectSysSupplierContactList(sysSupplierContact);
        ExcelUtil<SysSupplierContact> util = new ExcelUtil<SysSupplierContact>(SysSupplierContact.class);
        util.exportExcel(response, list, "服务商联系方式数据");
    }

    /**
     * 获取服务商联系方式详细信息
     */
    @ApiOperation(value = "获取服务商联系方式详细信息")
   // @PreAuthorize("@ss.hasPermi('system:contact:query')")
    @GetMapping(value = "/{contactId}")
    public AjaxResult getInfo(@PathVariable("contactId") Long contactId)
    {
        return AjaxResult.success(sysSupplierContactService.selectSysSupplierContactByContactId(contactId));
    }

    /**
     * 新增服务商联系方式
     */
    @ApiOperation(value = "新增服务商联系方式")
 //   @PreAuthorize("@ss.hasPermi('system:contact:add')")
    @Log(title = "服务商联系方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSupplierContact sysSupplierContact)
    {
        return toAjax(sysSupplierContactService.insertSysSupplierContact(sysSupplierContact));
    }

    /**
     * 修改服务商联系方式
     */
    @ApiOperation(value = "修改服务商联系方式")
  //  @PreAuthorize("@ss.hasPermi('system:contact:edit')")
    @Log(title = "服务商联系方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSupplierContact sysSupplierContact)
    {
        return toAjax(sysSupplierContactService.updateSysSupplierContact(sysSupplierContact));
    }

    /**
     * 删除服务商联系方式
     */
    @ApiOperation(value = "删除服务商联系方式")
  //  @PreAuthorize("@ss.hasPermi('system:contact:remove')")
    @Log(title = "服务商联系方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contactIds}")
    public AjaxResult remove(@PathVariable Long[] contactIds)
    {
        return toAjax(sysSupplierContactService.deleteSysSupplierContactByContactIds(contactIds));
    }
}
